package com.dhj.yygh.mongo_operation;

import com.dhj.yygh.model.hosp.Hospital;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

/*
HospitalRepository 太过于抽象，结合手动编写的 MyMongoTemplate 便于理解
 */
@Repository
public class MyMongoTemplate {
    @Autowired
    MongoTemplate template;

    // 根据医院 hoscode 获取医院信息
    public Hospital findHospitalByHoscode(String hoscode) {
        Query query = new Query(Criteria.where("hoscode").is(hoscode));
        return template.findOne(query, Hospital.class);
    }
}
